// columns.ts

import DictTag, { DictValueEnum } from "@/components/DictTag";
import { createIcon } from "@/utils/IconUtil";
import { ProColumns } from "@ant-design/pro-table";
import { Divider, Popconfirm, Space, Switch, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	statusOptions: DictValueEnum,
	handleColumnEditor: (record: API.Setting.DeptVo) => void,
	handleColumnRemove: (record: API.Setting.DeptVo) => void
): ProColumns<API.Setting.DeptVo>[] => {
	return [
		{
			title: "部门名称",
			dataIndex: "deptName",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "部门负责人",
			dataIndex: "leaderName",
			hideInSearch: true,
			valueType: "text"
		},
		{
			title: "联系电话",
			dataIndex: "phone",
			valueType: "text"
		},
		{
			title: "联系邮箱",
			dataIndex: "email",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "排序",
			dataIndex: "sort",
			valueType: "text",
			hideInSearch: true,
			sorter: (a, b) => a.sort - b.sort
		},
		{
			title: "状态",
			dataIndex: "status",
			valueType: "select",
			valueEnum: statusOptions,
			render: (_, record) => {
				return <DictTag enums={statusOptions} type="badge" value={record.status} />;
			}
		},
		{
			title: "操作",
			dataIndex: "option",
			width: "220px",
			valueType: "option",
			render: (_, record: any) => {
				return (
					<>
						<Space size={2} split={<Divider type="vertical" />}>
							<Typography.Link key="edit" onClick={() => handleColumnEditor(record)}>
								编辑
							</Typography.Link>
							<Popconfirm
								placement="bottomRight"
								title="提示"
								description={`确定要删除此 "${record.deptName}" 部门吗？`}
								onConfirm={async () => handleColumnRemove(record)}
								okText="确认"
								cancelText="取消"
							>
								<Typography.Link type="danger" key="remove">
									删除
								</Typography.Link>
							</Popconfirm>
						</Space>
					</>
				);
			}
		}
	];
};

export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const formTitle = ["创建部门", "编辑部门"];
